# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('xz-git' 'liblzma-git' 'liblzma-devel-git')
_realname=xz
_ver_base=5.2.1
pkgver=5.2.1.1126.c2e29f0
pkgrel=1
pkgdesc='Library and command line tools for XZ and LZMA compressed files'
arch=('i686' 'x86_64')
url='https://tukaani.org/xz/'
license=('GPL' 'LGPL' 'custom')
depends=('sh' 'libiconv' 'gettext')
makedepends=('libiconv-devel' 'gettext-devel')
options=('staticlibs')
source=("git+https://git.tukaani.org/xz.git")
sha256sums=('SKIP')

pkgver() {
  cd ${srcdir}/${_realname}
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
  ./autogen.sh
}

build() {
  cd ${srcdir}/${_realname}

  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static
  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd ${srcdir}/${_realname}
  make check
}

package_xz-git() {
  groups=('compression')
  depends=("liblzma-git=${pkgver}" 'libiconv' 'libintl')
  provides=('xz')
  conflicts=('xz')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*.dll
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/

  #install -d -m755 ${pkgdir}/usr/share/licenses/xz/
  #ln -sf /usr/share/doc/xz/COPYING ${pkgdir}/usr/share/licenses/xz/
  #ln -sf /usr/share/licenses/common/GPL2/license.txt ${pkgdir}/usr/share/doc/xz/COPYING.GPLv2
}

package_liblzma-git() {
  pkgdesc="Library for XZ and LZMA compressed files"
  groups=('libraries')
  provides=('liblzma')
  conflicts=('liblzma')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_liblzma-devel-git() {
  pkgdesc="Liblzma headers and libraries"
  groups=('development')
  depends=("liblzma-git=${pkgver}" 'libiconv-devel' 'gettext-devel')
  provides=('liblzma-devel')
  conflicts=('liblzma-devel')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
